home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mapplane.py < prev    next >
Text File  |  2004-01-05  |  6KB  |  217 lines

  1. """   QuArK  -  Quake Army Knife Bezier shape makers
  2.  
  3.  
  4. """
  5. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  6. # FOUND IN FILE "COPYING.TXT"
  7. #
  8.  
  9. #$Header: /cvsroot/quark/runtime/plugins/mapplane.py,v 1.3 2002/05/18 22:38:31 tiglari Exp $
  10.  
  11. Info = {
  12.    "plug-in":       "Three Pooint Plane plugin",
  13.    "desc":          "Define a plane from three points",
  14.    "date":          "May 25, 2001",
  15.    "author":        "tiglari",
  16.    "author e-mail": "tiglari@planetquake.com",
  17.    "quark":         "Version 6.3"
  18. }
  19.  
  20.  
  21. import quarkx
  22. import quarkpy.mapmenus
  23. import quarkpy.mapentities
  24. import quarkpy.mapeditor
  25. import quarkpy.mapcommands
  26. import quarkpy.mapoptions
  27. import quarkpy.maphandles
  28. import quarkpy.dlgclasses
  29. import quarkpy.mapduplicator
  30. StandardDuplicator = quarkpy.mapduplicator.StandardDuplicator
  31. from quarkpy.maputils import *
  32. from tagging import *
  33.  
  34. class PlaneHandle(quarkpy.maphandles.CenterHandle):
  35.  
  36.     def __init__(self, pos, dup, color):
  37.         self.dup=dup
  38.         quarkpy.maphandles.CenterHandle.__init__(self,pos,dup,color)
  39.  
  40.     def menu(self, editor, view):
  41.         oldmenu = quarkpy.maphandles.CenterHandle.menu(self, editor, view)
  42.  
  43.         def tagplane(m,self=self, editor=editor):
  44.             p0,p1,p2,p3=self.pozzies()
  45.             tagplane((p1,p2,p3),editor)
  46.  
  47.         def glueplane(m, self=self, editor=editor):
  48.             p1,p2,p3=editor.tagging.taggedplane
  49.             plane=self.centerof
  50.             undo=quarkx.action()
  51.             for (spec,val) in (("P1", p1), ("P2",p2), ("P3",p3)):
  52.                  undo.setspec(plane,spec,val.tuple)                 
  53.             editor.ok(undo,"Glue plane to tagged")            
  54.  
  55.         tagitem = qmenu.item("Tag Plane",tagplane)
  56.         glueitem = qmenu.item("Glue to tagged plane", glueplane)
  57.  
  58.         tagged = gettaggedplane(editor)
  59.         if tagged is None:
  60.             glueitem.state=qmenu.disabled
  61.         return [tagitem, glueitem]+oldmenu
  62.  
  63.     def pozzies(self):
  64.         def getpos(spec,dup=self.dup):
  65.             return quarkx.vect(dup[spec])
  66.         points = map(getpos,("P1","P2","P3"))
  67.         return [reduce(lambda x,y:x+y,points)/3.0]+points
  68.  
  69.  
  70.  
  71. #
  72. #  --- Duplicators ---
  73. #
  74. class PlaneCenterHandle(PlaneHandle):
  75.     "A handle for accessing the center a plane."
  76.  
  77.     def __init__(self, dup):
  78.         self.dup=dup # gotto do this first
  79.         self.pos = self.pozzies()[0]
  80.         PlaneHandle.__init__(self, self.pos, dup, MapColor("Axis"))
  81.  
  82.     def drag(self, v1, v2, flags, view):
  83.         delta = v2-v1
  84.         dup = self.centerof
  85.         pos0 = self.pos
  86.         if flags&MB_CTRL:
  87.             newpos = aligntogrid(pos0+delta,1)
  88.         else:
  89.             delta = quarkpy.qhandles.aligntogrid(delta,1)
  90.             newpos = pos0+delta
  91.         newdelta = newpos-pos0
  92.         if delta or (flags&MB_REDIMAGE):
  93.             new = self.centerof.copy()
  94.             for spec in ("P1", "P2", "P3"):
  95.                 new[spec]=(quarkx.vect(new[spec])+newdelta).tuple
  96.             new = [new]
  97.         else:
  98.             new = None
  99.         return [self.centerof], new
  100.  
  101.     def draw(self, view, cv, draghandle=None):
  102.         quarkpy.maphandles.CenterHandle.draw(self,view,cv,draghandle)
  103.         #
  104.         # color-change isn't working. also why no show
  105.         #   during drag?
  106.         #
  107.         dyn = draghandle is self
  108.         if dyn:
  109.             pencolor = RED
  110.         else:
  111.             pencolor = 0xF0CAA6
  112.         pt = map(view.proj, self.pozzies())
  113.         cv.penwidth-2
  114.         cv.pencolor=pencolor
  115.         for i in (1,2,3):
  116.             cv.line(pt[0], pt[i])
  117.  
  118.  
  119. class PlanePointHandle(PlaneHandle):
  120.   "A point for defining a plane."
  121.  
  122.   def __init__(self, dup, spec):
  123.       self.spec=spec
  124.       pos = quarkx.vect(dup[spec])
  125.       PlaneHandle.__init__(self, pos, dup, MapColor("Axis"))
  126.  
  127.   def drag(self, v1, v2, flags, view):
  128.       delta = v2-v1
  129.       dup, spec = self.centerof, self.spec
  130.       pos0 = quarkx.vect(dup[spec])
  131.       if flags&MB_CTRL:
  132.           newpos = aligntogrid(pos0+delta,1)
  133.       else:
  134.           delta = quarkpy.qhandles.aligntogrid(delta,1)
  135.           newpos = pos0+delta
  136.       if delta or (flags&MB_REDIMAGE):
  137.           new = self.centerof.copy()
  138.           new[spec]=newpos.tuple
  139.           new = [new]
  140.       else:
  141.           new = None
  142.       return [self.centerof], new
  143.  
  144.  
  145. class PlaneDuplicator(StandardDuplicator):
  146.  
  147.     def buildimages(self):
  148.         return []
  149.  
  150.     def handles(self, editor, view):
  151.         def makehandle(spec,self=self):
  152.             return PlanePointHandle(self.dup,spec)
  153.         list = map(makehandle,["P1", "P2", "P3"])+[PlaneCenterHandle(self.dup)]
  154.         return list
  155.         
  156.  
  157. quarkpy.mapduplicator.DupCodes.update({
  158.   "dup plane":  PlaneDuplicator,
  159. })
  160.  
  161. #
  162. # Make a 3point plane from a tagged plane
  163. #
  164.  
  165. #
  166. # Probably not useful, but here it is anyway
  167. #
  168. def make3points(m):
  169.     editor=mapeditor()
  170.     if editor is None: return
  171.     #
  172.     # gettaggedplane returns a face, we want the points,
  173.     #  assumes item disabled if taggedplane nexistepas
  174.     #
  175.     p1,p2,p3=editor.tagging.taggedplane
  176.     plane = quarkx.newobj("plane duplicator:d")
  177.     plane["macro"]="dup plane"
  178.     for (spec,val) in (("P1", p1), ("P2",p2), ("P3",p3)):
  179. #         debug('spec '+spec+'; val: '+`val`)
  180.          plane[spec]=val.tuple
  181.     undo=quarkx.action()
  182.     sel = editor.layout.explorer.uniquesel
  183.     parent=sel.treeparent
  184.     while not parent.acceptitem(plane):
  185.        parent=parent.treeparent
  186.     undo.put(parent,plane,sel)
  187.     editor.ok(undo,"Create 3point plane")
  188.     editor.layout.explorer.uniquesel=plane
  189.  
  190. planeItem = qmenu.item("Plane from tagged points", make3points)
  191.  
  192. def commandsclick(menu, oldcommand=quarkpy.mapcommands.onclick):
  193.     editor=mapeditor()
  194.     if editor is None: return
  195.     plane=gettaggedplane(editor)
  196.     if plane is None:
  197.        planeItem.state=qmenu.disabled
  198.     else:
  199.        planeItem.state=qmenu.normal
  200.       
  201. #quarkpy.mapcommands.onclick = commandsclick
  202.  
  203. #quarkpy.mapcommands.items.append(planeItem)
  204.  
  205.  
  206. #$Log: mapplane.py,v $
  207. #Revision 1.3  2002/05/18 22:38:31  tiglari
  208. #remove debug statement
  209. #
  210. #Revision 1.2  2001/07/24 02:37:11  tiglari
  211. #glue plane to tagged plane
  212. #
  213. #Revision 1.1  2001/05/25 12:27:15  tiglari
  214. #tagged plane support
  215. #
  216. #
  217.